import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './routes.js'
import store from '@/store'

Vue.use(VueRouter);

// console.log( process.env.BASE_URL )

let router = new VueRouter({
    // linkActiveClass:"active",
    // linkExactActiveClass:"exact-active",
    base:process.env.BASE_URL,
    // mode:"history",
    routes: routes
});

let users = {}

// 在路由的配置中直接对路由对象进行守卫方法定义。设置的守卫功能是对所有路由生效
router.beforeEach(function(to,from,next){
    console.log("全局前置守卫")
    console.log("to:",to)
    console.log("from:",from)
    console.log("全局前置守卫调用vuex store:",store)
    users[to.path] = new Date().getTime()
    // if(to.meta.isPrivate){
    //     next(false);
    // }else{
    //     next();
    // }
    next();
})

// 全局后置钩子 = 不具有任何拦截功能 = 多用于路由访问统计
router.afterEach(function(to,from,next){
    console.log("全局后置钩子")
    console.log("to:",to)
    console.log("from:",from)
    console.log("next",next)
    console.log( from.path,":被访问了-",new Date().getTime()-users[to.path],"ms" );
})


export default router